package com.jucai.pppeiyouclient.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.Gravity;
import android.widget.TextView;

import com.jucai.pppeiyouclient.R;
import com.jucai.pppeiyouclient.base.CommonRecyclerViewAdapter;
import com.jucai.pppeiyouclient.bean.OrderBean;
import com.jucai.pppeiyouclient.utils.ScreenUtil;
import com.jucai.pppeiyouclient.weidget.taglayout.TagLayout;

import java.util.List;

/**
 * Created by Kuky on 2017-04-20.
 */

public class ListOrderAdapter extends CommonRecyclerViewAdapter<OrderBean> {

    public ListOrderAdapter(Context context, List<OrderBean> data) {
        super(context, data);
    }

    @Override
    public void bindHolder(CommonHolder holder, OrderBean orderBean) {
        holder.setIsRecyclable(false);
        holder.setImage(R.id.order_user_img, orderBean.getMember_avatar(), 60, 60);
        holder.setText(R.id.order_user_name, orderBean.getMember_realname());
        holder.setText(R.id.order_user_info, orderBean.getMember_sexual() + "  " +
                orderBean.getMember_age() + "岁");
        holder.setText(R.id.order_start_time, "" + orderBean.getTorder_start_time());
        holder.setText(R.id.order_start_location, "" + orderBean.getTorder_start_point());
        holder.setText(R.id.order_create_time, orderBean.getTorder_create_time());

        TagLayout tagContainer = holder.getView(R.id.user_tag);
        holder.setVisible(R.id.user_tag);
        holder.setGone(R.id.order_state_str);

        String tags = orderBean.getMember_tags();
        String[] tagStr = tags.split(",");

        for (int i = 0; i < tagStr.length; i++) {
            if (TextUtils.equals(tagStr[i],"")) {
                continue;
            } else {

                TextView tag = new TextView(mContext);
                tag.setText(tagStr[i]);
                tag.setTextColor(Color.WHITE);
                tag.setTextSize(12);
                tag.setBackgroundResource(R.drawable.shape_round_corner_stroke_orange_4dp);
                tag.setPadding(ScreenUtil.dip2px(mContext, 10), ScreenUtil.dip2px(mContext, 5),
                        ScreenUtil.dip2px(mContext, 10), ScreenUtil.dip2px(mContext, 5));
                tag.setGravity(Gravity.CENTER);
                tagContainer.addView(tag);
            }
        }

        holder.setGone(R.id.order_number);
        holder.setGone(R.id.order_state);
        holder.setGone(R.id.order_end);
    }

    @Override
    protected int getItemType(int position) {
        return 0;
    }

    @Override
    public int getLayoutId(int viewType) {
        return R.layout.item_order_layout_list;
    }
}
